package com.clothing.customization.controller.admin;

import com.clothing.customization.common.ApiResponse;
import com.clothing.customization.service.OrderAnalysisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;

/**
 * 订单分析控制器
 */
@RestController
@RequestMapping("/api/admin/orders")
@CrossOrigin(origins = "*", allowedHeaders = "*")
public class OrderAnalysisController {

    @Autowired
    private OrderAnalysisService orderAnalysisService;

    /**
     * 获取订单趋势数据
     */
    @GetMapping("/trend")
    public ApiResponse getTrendData(
            @RequestParam String type,
            @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date startDate,
            @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date endDate) {
        Map<String, Object> data = orderAnalysisService.getOrderTrend(type, startDate, endDate);
        return ApiResponse.success(data);
    }

    /**
     * 获取订单分布数据
     */
    @GetMapping("/distribution")
    public ApiResponse getDistributionData(
            @RequestParam String type,
            @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date startDate,
            @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date endDate) {
        Map<String, Object> data = orderAnalysisService.getOrderDistribution(type, startDate, endDate);
        return ApiResponse.success(data);
    }

    /**
     * 获取订单明细数据
     */
    @GetMapping("/details")
    public ApiResponse getOrderDetails(
            @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date startDate,
            @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date endDate,
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        Map<String, Object> data = orderAnalysisService.getOrderDetails(startDate, endDate, page, pageSize);
        return ApiResponse.success(data);
    }
} 